package com.zp.self.module.level_4_算法练习.数据结构.hash表;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author By ZengPeng
 */
public class 力扣_500_键盘行 {
    //测试
    public static void main(String[] args) {


        String[] ints = new 力扣_500_键盘行().findWords(new String[]{"Hello","Alaska","Dad","Peace"});
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]+",");
        }

        System.out.println();

        ints = new 力扣_500_键盘行().findWords(new String[]{"omk"});
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]+",");
        }

        System.out.println();

        ints = new 力扣_500_键盘行().findWords(new String[]{"adsdf","sfd"});
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]+",");
        }
    }

    /*
    题目：
        给你一个字符串数组 words ，只返回可以使用在 美式键盘 同一行的字母打印出来的单词。键盘如下图所示。
        美式键盘 中：
        第一行由字符 "qwertyuiop" 组成。
        第二行由字符 "asdfghjkl" 组成。
        第三行由字符 "zxcvbnm" 组成。

        示例 1：
        输入：words = ["Hello","Alaska","Dad","Peace"]
        输出：["Alaska","Dad"]

        示例 2：
        输入：words = ["omk"]
        输出：[]

        示例 3：
        输入：words = ["adsdf","sfd"]
        输出：["adsdf","sfd"]

    分析：【perfect】
       1.创建3个set集合 ，通过hash判断是否存储在

    边界值 & 注意点：
       1.注意一个字符
    */
    public String[] findWords(String[] words) {
        List<Character> characterList1 = Arrays.asList('q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P');
        List<Character> characterList2 = Arrays.asList('a','s','d','f','g','h','j','k','l','A','S','D','F','G','H','J','K','L');
        List<Character> characterList3 = Arrays.asList('z','x','c','v','b','n','m','Z','X','C','V','B','N','M');

        List<String> res = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if(word.length()==1){
                res.add(word);continue;
            }
            char c = word.charAt(0);
            List<Character> targetList ;
            if(characterList1.contains(c))targetList = characterList1;
            else if (characterList2.contains(c))targetList = characterList2;
            else targetList = characterList3;

            for (int j = 1; j < word.length(); j++) {
                if(!targetList.contains(word.charAt(j)))break;
                if(j==word.length()-1)res.add(word);
            }
        }
        String[] devOnlyIds = new String[res.size()];
        res.toArray(devOnlyIds);
        return devOnlyIds;
    }
}
